package org.gap.wizards;

import net.slashie.libjcsi.ConsoleSystemInterface;
import net.slashie.libjcsi.textcomponents.LabelProvider;
import net.slashie.libjcsi.textcomponents.ListBox;

import org.gap.jseed.injection.annotation.Singleton;
import org.gap.wizards.items.Inventory;
import org.gap.wizards.items.Item;
import org.gap.wizards.pc.PlayerCharacter;
import org.gap.wizards.state.TransitionState;
import org.gap.wizards.views.ViewPlatform;
import org.gap.wizards.views.ViewPlatform.Color;

@Singleton
public class InventoryViewState implements TransitionState {
	private final PlayerCharacter character;
	private ListBox<Item> listBox;
	private Inventory inventory;

	public InventoryViewState(PlayerCharacter character, ConsoleSystemInterface csi) {
		this.character = character;
		listBox = new ListBox<Item>(csi);
		listBox.setBorder(false);
		listBox.setBounds(5, 3, 80, 32);
		listBox.setLabelProvider(new ItemsLabelProvider());
	}
	
	@Override
	public void acceptKey(char keyPress) {
	}

	@Override
	public void draw(ViewPlatform console) {
		console.print(5, 1, Color.YELLOW, "$" + inventory.getTotalMoney());
		listBox.draw();
	}
	
	@Override
	public void enter() {
		inventory = character.getInventory();
		listBox.setElements(inventory.allItems());
	}

	@Override
	public void exit() {
		listBox.clearElements();
	}

	/**
	 * Simple default label provider for now.
	 * @author gpelcha
	 *
	 */
	public class ItemsLabelProvider implements LabelProvider<Item> {
		@Override
		public String getText(Item item) {
			return item.toString();
		}
	}
}
